import React from 'react';
import { Button, message } from 'antd';
import ProForm, {
  ModalForm,
  ProFormText,
  ProFormDateRangePicker,
  ProFormSelect,
} from '@ant-design/pro-form';
import { PlusOutlined } from '@ant-design/icons';
import { request } from 'umi';
import { api } from '@/global';

const waitTime = (time: number = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};

export default () => {
  return (
    <ModalForm<{
      name: string;
      company: string;
    }>
      title="新建表单"
      trigger={<Button type="primary">修改密码</Button>}
      autoFocusFirstInput
      modalProps={{
        onCancel: () => console.log('run'),
      }}
      onFinish={async (values: any) => {
        const { checkagin, password } = values;

        if (checkagin != password) {
          message.error('请再次确认密码是否一致');
          return;
        }

        const result = await request(api.modifyPrivatePassword, {
          method: 'POST',
          data: {
            ...values,
          },
        });

        if (result.success) {
          message.success('修改成功');

          return true;
        } else {
          message.error('修改失败');
          return;
        }
      }}
    >
      <ProFormText
        width="md"
        name="password"
        label="请输入修改的密码"
        tooltip="至少8个字符，至少1个大写字母，1个小写字母和1个数字,不能包含特殊字符（非数字字母）"
        placeholder="请输入密码"
        rules={[
          { required: true },
          {
            pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/,
            message: '密码格式错误',
          },
        ]}
      />

      <ProFormText width="md" name="checkagin" label="再次输入进行验证" />
    </ModalForm>
  );
};
